Determine installed PowerShell version

Use $PSVersionTable.PSVersion to determine the engine version. If the variable does not exist, it is safe to assume the engine is version 1.0. Note that $Host.Version and (Get-Host).Version are not reliable – they reflect the version of the host only, not the engine. PowerGUI, PowerShellPLUS, etc. are all hosting applications, and they will set the … Read more

Need to extract value of attribute from xml from Command promt [closed]

There are literally tons of sample scripts, and docs all over the web explaining and showing how to deal with this use case… Example: https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-data-basics-xml … including discussions on this site. Though the XML snippet is not complete and you should really provide a more complete one, one can assume what it would look like. … Read more

Monitor all print queue job

Use the classes in the System.Printing namespace, for example: Local: Add-Type -AssemblyName “System.Printing” [System.Printing.LocalPrintServer]::GetDefaultPrintQueue() Or remote: Add-Type -AssemblyName “System.Printing” [System.Printing.PrintServer]::new(“\\$computerName”, [System.Printing.PrintSystemDesiredAccess]::AdministrateServer) You can also use the PrintManagement PowerShell module: Import-Module “PrintManagement” $printers = Get-Printer -ComputerName $computerName Get-PrintJob -ComputerName $computerName -PrinterName $printers[0].Name

PowerShell expression

It takes the contents of a file ‘InputName’, runs it through a regular expression and outputs it to the file ‘OutputName’. The expression takes something in front of a comma, plus the comma itself and concatenates it with something that’s behind a double backslash, some text, a backslash, some text and another backslash. So it … Read more

this code my teacher gave it to us as homework and it does not work with me idk why

VonPryz is correct, Please try the below code Write-Host “checking users” $testUser=”hgallo” $checkUser = Get-WmiObject -Class Win32_UserAccount -Filter “LocalAccount=”True”” | Select-String -Pattern $testUser if($checkUser -ne $null) { Write-Host “user $testUser found” } else { Write-Host “user $testUser not found” } The error in the code was stating that the -Pattern parameter was failing because the … Read more

How to delete subfolders and Files but not parent Folder in windows using Script? [closed]

As PowerShell supports wildcards/patterns on multiple levels of a path, it’s as simple as: Get-ChildItem D:\test[1-3]\* | Remove-Item -Recurse -Force Sample tree before and after running the command: > tree /F D:. ├───test1 │ └───test1 │ └───archive │ x.txt │ ├───test2 │ └───try │ └───archive │ x.txt │ └───test3 └───model └───archive x.txt > Get-ChildItem D:\test[1-3]\*|Remove-Item … Read more