Hello I am using below scriptblock and have passed variable name “localfolderpath” where while testing path it is coming null . could you please suggest what I am missing here . Due to this we are unable to folder for users who do not have it on server.
$ScriptBlockDir = {
Param (
[string] $samAccountName )
if( $Env:ComputerName -eq "fileserver101" ) {
$LocalFolderPath = "H:\Users"
}
else {
$LocalFolderPath = "D:\Users"
}
if( -not (test-path -Path "$LocalFolderPath\$samAccountName") ) {
try {
LogEntry "New Home Drive Folder"
$NewFolder = New-Item -Path $LocalFolderPath -Name $samAccountName -ItemType Directory
return 1
}
catch {
Write-Host "Failed with error"
return -1
}
}
Write-Host "already exists"
return 0
}
$result = Invoke-Command -Session $PSSession -ScriptBlock $ScriptBlockDir -ArgumentList $samAccountName