locked
Problems with a PS script RRS feed

  • Question

  • Complete novice on PS here.  however i have a script that i wrote to pull certain files off of windows 7 and windows 10 laptops.  The script works perfectly on windows 7 but not on windows 10.  The code i have is below:

        

    $date = Get-Date -UFormat %m%d%Y

    #Gets and assigns the drive letter for the backup destination, located on the USB drive.
    $winpe = Get-WmiObject win32_logicaldisk -filter "VolumeName = 'WINPE'"
    $servicetag = Get-WmiObject win32_bios
    $tag = $servicetag.serialnumber
    $a = $winpe.DeviceID
    $dest = "$a\Backups\$tag-$date"

    #Gets and assigns the drive letter for the Hard Drive.
    $hdd = Get-WmiObject win32_logicaldisk -Filter "VolumeName = 'OSDISK'"
    $d = $hdd.DeviceID

    #If backup for current date has been created, stop script.  Else, backup files.
    if (Test-Path $dest){
        Write-Host "Backup already completed." 
        break
        } else {

      cd $d

      I get an error on windows 10 that says "

    cd : Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
    At line:2 char:3
    +   cd $d
    +   ~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-Location], PSArgumentNullException
        + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SetLocationCommand

    I'm assuming that it has something to do with changing the directory but it works fine on windows 7.  any help would be greatly appreciated.  t

     
    Thursday, February 7, 2019 3:17 PM

All replies

  • Plaese format your code as code here in the forum using the code posting tool provided on the edit bar of the post editor. Thanks.

    It seems like there is no volume with the name  "OSDISK" on your W10 machine. Therefor the variable $hdd is empty therefor the variable $d is empty therefor the command cd $d misses the path.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by jrv Thursday, February 7, 2019 5:05 PM
    Thursday, February 7, 2019 4:44 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, February 21, 2019 7:23 AM