Clayton commented on
How to build a PowerShell inventory script for Windows Servers 2 years, 9 months ago
The final block of code should be more like the following.
Users might need to enable PSRemotting and have admin credentials to connect to the server/workstation.
[CmdletBinding()] param( [Parameter()] [ValidateNotNullOrEmpty()] [string[]]$Servers ) foreach ($server in $servers) { $output = [ordered]@{ 'ServerName' = $server 'OperatingSystem' = (Get-CimInstance -ComputerName $server -ClassName Win32_OperatingSystem).Caption 'FreeDiskSpace (GB)' = [Math]::Round(((Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),1) 'Memory (GB)' = (Get-CimInstance -ComputerName $server -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum /1GB } [pscustomobject]$output }
Clayton commented on
Managing Services the PowerShell way – Part 1: Get Service status 3 years, 8 months ago
You can use the following command in a batch file. The only need for this style of calling Powershell would be needed when using Powershell commands in conjunction with other batch commands…
Just update the NAME_OF_FILE, the script will get the local path using the %~dp0 in-front of the filename.ps1.
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dp0NAME_OF_FILE.ps1""' -Verb RunAs}"
Clayton liked comment of sri on Managing Services the PowerShell way – Part 1: Get Service status. (So far, sri has 1 likes for this comment.) 3 years, 8 months ago
By creating GUIs with PowerShell in this manner, is it reliant on the .NET framework version a user is using?
Clayton commented on
PowerShell script to query file versions on remote computers 3 years, 11 months ago
You could add the items in the txt file as you did. Then you could put do a foreach loop for the files and run the QueryFileVersionsRemotely.ps1 file.
$files = Get-Content C:pathtofiles.txt Foreach($line in $files){ .QueryFileVersionsRemotely.ps1 -ComputerName (Get-Content D:TempComputerlist.txt) -Path $line -OutputFile C:TempFileVersionInfo.csv }
The $line Variable should be the full path of the file. The trick is now to find a way to rename the output file to a different name for each file type.
Or if the files are in the same directory you could pipe the command as well.
ls | .QueryFileVersionsRemotely.ps1 -ComputerName (Get-Content D:TempComputerlist.txt) -Path "." -OutputFile C:TempFileVersionInfo.csv
Clayton liked comment of Puma on PowerShell script to query file versions on remote computers. (So far, Puma has 2 likes for this comment.) 3 years, 11 months ago
Since you are saving the file as “WindowsProfiles.ps1” that will be what you need to call in the console. in the example above, the author saved the file as “Get-WindowsProfiles.ps1”. That is why you are getting the error you stated.
Clayton liked comment of D on