PowerShell

Desktop

Get Zip Archive Unzip And RenameZip File


    Function Name-File {
        $fname = (Get-Date).ToShortDateString().Replace("/","-")
        $fname
    }

    $x = name-file
        
    $ZipPath = "C:\temp\unzip"
    $ZipFile = "sss.zip"
    if(Test-Path "$ZipPath\$ZipFile" ){

        Expand-Archive -Path "$ZipPath\$ZipFile" -DestinationPath $ZipPath 
        Rename-Item -Path  "$ZipPath\$ZipFile" -NewName "$x.zip"

    }else{Write-Output "file does not exist"}
    

Creating a GUID


[guid]::newguid()

Getting the date from the day of year

You can use (Get-Date).DayOfYear to find the day of year.
I have used this to name folders and files. However it is nice to know how to convert the day of year into a date that is easy to recognize.

One way to do this is:

([datetime]"01/01/$((Get-Date).Year)").AddDays(267-1)

Where 267 is the day of the year


Adding A Computer To the domain and renaming it in one step

    Add-Computer -DomainName parma.internal -NewName NewComputer01 -OUPath "OU=companyComputers,DC=company,DC=pri" -Credential (Get-Credential)