Calculate difference in time using New-TimeSpan fails only in script [duplicate]
This question already has an answer here:
New Object PSCredential not working - using Unicode punctuation syntactically
2 answers
Powershell and UTF-8
2 answers
In my script test.ps1
I try to calculate the difference in time by using the New-TimeSpan
function:
$foo = "00:06:45.0"
$bar = "00:10:44.0"
$StartDate=[datetime]"01/01/2018 $foo"
$EndDate=[datetime]"01/01/2018 $bar"
Write-Output ($StartDate)
Write-Output ($EndDate)
NEW-TIMESPAN –Start $StartDate –End $EndDate
When I run the script, I get the (German) error:
New-TimeSpan : Es wurde kein Positionsparameter gefunden, der das Argument "â€Start 01/01/2018 00:06:45 â€End"
akzeptiert.
In C:UsersmeDownloadstest.ps1:8 Zeichen:1
+ NEW-TIMESPAN –Start $StartDate –End $EndDate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewTimeSpanCommand
What makes me wonder are the strange characters in the string â€
?!
When I enter all the commands step by step in the PowerShell directly, it works without any problems.
Do you know what could be the issue here? Thanks!
windows powershell utf-8 character-encoding
marked as duplicate by Jeroen Mostert, mklement0
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 14:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
New Object PSCredential not working - using Unicode punctuation syntactically
2 answers
Powershell and UTF-8
2 answers
In my script test.ps1
I try to calculate the difference in time by using the New-TimeSpan
function:
$foo = "00:06:45.0"
$bar = "00:10:44.0"
$StartDate=[datetime]"01/01/2018 $foo"
$EndDate=[datetime]"01/01/2018 $bar"
Write-Output ($StartDate)
Write-Output ($EndDate)
NEW-TIMESPAN –Start $StartDate –End $EndDate
When I run the script, I get the (German) error:
New-TimeSpan : Es wurde kein Positionsparameter gefunden, der das Argument "â€Start 01/01/2018 00:06:45 â€End"
akzeptiert.
In C:UsersmeDownloadstest.ps1:8 Zeichen:1
+ NEW-TIMESPAN –Start $StartDate –End $EndDate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewTimeSpanCommand
What makes me wonder are the strange characters in the string â€
?!
When I enter all the commands step by step in the PowerShell directly, it works without any problems.
Do you know what could be the issue here? Thanks!
windows powershell utf-8 character-encoding
marked as duplicate by Jeroen Mostert, mklement0
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 14:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
6
That–
is U+2013 EN DASH, and that's not the same thing as-
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your.ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.
– Jeroen Mostert
Nov 15 '18 at 13:23
1
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35
add a comment |
This question already has an answer here:
New Object PSCredential not working - using Unicode punctuation syntactically
2 answers
Powershell and UTF-8
2 answers
In my script test.ps1
I try to calculate the difference in time by using the New-TimeSpan
function:
$foo = "00:06:45.0"
$bar = "00:10:44.0"
$StartDate=[datetime]"01/01/2018 $foo"
$EndDate=[datetime]"01/01/2018 $bar"
Write-Output ($StartDate)
Write-Output ($EndDate)
NEW-TIMESPAN –Start $StartDate –End $EndDate
When I run the script, I get the (German) error:
New-TimeSpan : Es wurde kein Positionsparameter gefunden, der das Argument "â€Start 01/01/2018 00:06:45 â€End"
akzeptiert.
In C:UsersmeDownloadstest.ps1:8 Zeichen:1
+ NEW-TIMESPAN –Start $StartDate –End $EndDate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewTimeSpanCommand
What makes me wonder are the strange characters in the string â€
?!
When I enter all the commands step by step in the PowerShell directly, it works without any problems.
Do you know what could be the issue here? Thanks!
windows powershell utf-8 character-encoding
This question already has an answer here:
New Object PSCredential not working - using Unicode punctuation syntactically
2 answers
Powershell and UTF-8
2 answers
In my script test.ps1
I try to calculate the difference in time by using the New-TimeSpan
function:
$foo = "00:06:45.0"
$bar = "00:10:44.0"
$StartDate=[datetime]"01/01/2018 $foo"
$EndDate=[datetime]"01/01/2018 $bar"
Write-Output ($StartDate)
Write-Output ($EndDate)
NEW-TIMESPAN –Start $StartDate –End $EndDate
When I run the script, I get the (German) error:
New-TimeSpan : Es wurde kein Positionsparameter gefunden, der das Argument "â€Start 01/01/2018 00:06:45 â€End"
akzeptiert.
In C:UsersmeDownloadstest.ps1:8 Zeichen:1
+ NEW-TIMESPAN –Start $StartDate –End $EndDate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewTimeSpanCommand
What makes me wonder are the strange characters in the string â€
?!
When I enter all the commands step by step in the PowerShell directly, it works without any problems.
Do you know what could be the issue here? Thanks!
This question already has an answer here:
New Object PSCredential not working - using Unicode punctuation syntactically
2 answers
Powershell and UTF-8
2 answers
windows powershell utf-8 character-encoding
windows powershell utf-8 character-encoding
edited Nov 15 '18 at 14:39
mklement0
135k21252289
135k21252289
asked Nov 15 '18 at 13:18
ErandoErando
1981520
1981520
marked as duplicate by Jeroen Mostert, mklement0
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 14:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Jeroen Mostert, mklement0
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 14:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
6
That–
is U+2013 EN DASH, and that's not the same thing as-
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your.ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.
– Jeroen Mostert
Nov 15 '18 at 13:23
1
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35
add a comment |
6
That–
is U+2013 EN DASH, and that's not the same thing as-
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your.ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.
– Jeroen Mostert
Nov 15 '18 at 13:23
1
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35
6
6
That
–
is U+2013 EN DASH, and that's not the same thing as -
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your .ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.– Jeroen Mostert
Nov 15 '18 at 13:23
That
–
is U+2013 EN DASH, and that's not the same thing as -
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your .ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.– Jeroen Mostert
Nov 15 '18 at 13:23
1
1
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
6
That
–
is U+2013 EN DASH, and that's not the same thing as-
, U+002D HYPHEN-MINUS. PowerShell does accept it if it can make sense of the encoding (it works from the command line) but your.ps1
is probably saved as UTF-8 without a byte order mark, causing it to be wrongly detected as Windows-1252 (or whatever your system's default encoding is). Save the file as Unicode, UTF-8 without a BOM or (arguably best) avoid Unicode dashes.– Jeroen Mostert
Nov 15 '18 at 13:23
1
Erratum: "UTF-8 with a BOM".
– Jeroen Mostert
Nov 15 '18 at 13:33
Oh for God's sake! I knew it could only be a minor mistake but I couldn't find it. I'm a copy&paste guy and if I would have typed the command myself with my keyboard I wouldn't have used the wrong dash... thank you so very much!
– Erando
Nov 15 '18 at 13:35